#include "GameScreen.h"
#include "math.h"

using namespace cocos2d;

bool CGameScreen::init()
{
	if ( !CCLayer::init() )
	{
		return false;
	}
	
	BuildGround();

	return true;
}

cocos2d::CCScene* CGameScreen::scene()
{
	CCScene *pScene = CCScene::create();
	CGameScreen* pLayer = CGameScreen::create();
	pScene->addChild(pLayer);

	return pScene;
}

void CGameScreen::BuildGround()
{
	CCSize size = CCDirector::sharedDirector()->getWinSize();

	float nPos = 0.0;

	while(nPos < size.width)
	{	
		CCTexture2D* pTexture = new CCTexture2D();
		CCImage img;
		img.initWithImageFile("ground_piece.png");
		pTexture->initWithImage(&img);
		CCSprite* pSprite = CCSprite::initWithTexture(pTexture, CCRect(0,0));
		pSprite->setAnchorPoint(ccp(0,0));
		pSprite->setScaleY(0.5f);
		float scale = (1+0.1f*sin(nPos/15))/2;
		pSprite->setScaleY(scale);
		pSprite->setPosition(ccp(nPos, 0));		
		//this->addChild(pSprite, 0);
		AddNewPhysicsObject(pSprite);
		nPos += 2.0f;
	}
}